<?php

namespace app\admin\model\trades\order;

use think\Db;
use think\Model;


class Gainlog extends Model
{

    //支付状态
    const GAINLOG_STATE_1 = 1;//待确定
    const GAINLOG_STATE_2 = 2;//已确定
    const GAINLOG_STATE_3 = 3;//已退款


    // 表名
    protected $table = 'activity_gain_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'ctime_text'
    ];
    

    



    public function getCtimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ctime']) ? $data['ctime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setCtimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    /*
     * 更新收益详情表
     */
    public static function update_gain_log($oid){
        Db::table('activity_gain_log')->where('orderid', $oid)->update(['state'=>2]);
        return true;
    }

}
